﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>2. 设置报表显示列</title>
    <link href="../../Scripts/bootstrap/bootstrap-table/dist/bootstrap-table.min.css" rel="stylesheet" />
    <script src="../../Scripts/bootstrap/bootstrap-table/dist/bootstrap-table.min.js"></script>
    <script src="../../Scripts/easyUI/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="../../Scripts/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../Comm/Gener.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">

        //页面启动函数.
        $(function () {

            $("#Msg").html("<img src=../../../Img/loading.gif />&nbsp;正在加载,请稍后......");

            InitPage();

            $("#Msg").html("");

        });

        //返回类型.
        function GenerRptMark() {
            var rptNo = unescape(GetQueryString("RptNo"));
            var flowNo = unescape(GetQueryString("FK_Flow"));
            var rptMark = rptNo.substr(('ND' + parseInt(flowNo) + 'Rpt').length);
            return rptMark;
        }

        function InitPage() {

            var rptNo = unescape(GetQueryString("RptNo"));
            var flowNo = unescape(GetQueryString("FK_Flow"));

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_RptDfine");
            handler.AddPara("RptNo", rptNo);
            handler.AddPara("FK_Flow", flowNo);
            var data = handler.DoMethodReturnString("S2ColsChose_Init");

            if (data.indexOf("@") == 0) {
                alert(data);
                return;
            }

            var jsData = JSON.parse(data);
            var Sys_MapAttrOfAll = jsData["Sys_MapAttrOfAll"]; //所有的列.
            var Sys_MapAttrOfSelected = jsData["Sys_MapAttrOfSelected"]; //已经选择的列.
            var Sys_MapAttrOfSystem = jsData["Sys_MapAttrOfSystem"]; //系统字段.
            var rptMark = GenerRptMark(); //rptNo.substr(('ND' + parseInt(flowNo) + 'Rpt').length);
            var dis = ' disabled="disabled"';
            var tsysAppend = "",
                tallAppend = "";


            //1.列出系统字段（过滤掉必选字段）
            $.grep(Sys_MapAttrOfSystem, function (item) {
                return item.KeyOfEn == "Title" || item.KeyOfEn == "OID"
                    || item.KeyOfEn == "WFState"
                    || item.KeyOfEn == "FlowStartRDT"
                    || item.KeyOfEn == "FK_Dept"
                    || item.KeyOfEn == "FlowEmps" || item.KeyOfEn == "FlowStarter";
            }, true).forEach(function (item, index) {

                if (index % 3 == 0) {
                    tsysAppend += "<tr>";
                }

                tsysAppend += "<td nowrap style='width:33%'>";
                var flag = false;
                var disstr = '';

                switch (rptMark) {
                    case "My":
                        if (item.KeyOfEn == "FlowStarter") {
                            flag = true;
                            disstr = dis;
                        }
                        if (item.KeyOfEn == "FlowEmps") {
                            flag = true;
                            disstr = dis;
                        }
                        break;
                    case "MyDept":
                        if (item.KeyOfEn == "FK_Dept") {
                            flag = true;
                            disstr = dis;
                        }
                        break;
                    case "MyJoin":
                        break;
                }

                for (var i = 0, length = Sys_MapAttrOfSelected.length; i < length; i++) {
                    if (item.KeyOfEn == Sys_MapAttrOfSelected[i].KeyOfEn && item.Name == Sys_MapAttrOfSelected[i].Name) {
                        flag = true;
                        break;
                    }
                }
                tsysAppend += "<input id='" + item.KeyOfEn + "' type='checkbox' name='" + item.KeyOfEn + "' " + (flag ? "checked = 'checked'" : "") + disstr + " />";
                tsysAppend += "<label for='" + item.KeyOfEn + "'>" + item.Name + "(" + item.KeyOfEn + ")</label>";
                tsysAppend += "</td>";

                if (index % 3 == 2) {
                    tsysAppend += "</tr>";
                }
            });
            $("#tsys").append(tsysAppend);

            //2.列出业务字段
            $.grep(Sys_MapAttrOfAll, function (item) {
                var flag = false;



                if (item.UIContralType == 4 || item.UIContralType == 6 || item.UIContralType == 8 || item.UIContralType == 9
                    || item.UIContralType == 11 || item.UIContralType == 50 || item.UIContralType == 60 || item.UIContralType == 101)
                    return true;
                for (var i = 0, length = Sys_MapAttrOfSystem.length; i < length; i++) {
                    if (item.KeyOfEn == Sys_MapAttrOfSystem[i].KeyOfEn && item.Name == Sys_MapAttrOfSystem[i].Name) {
                        flag = true;
                        break;
                    }
                }
                return flag;
            }, true).forEach(function (item, index) {

                if (index % 3 == 0) {
                    tallAppend += "<tr>";
                }

                tallAppend += "<td nowrap style='width: 33%'>";
                var flag = false;
                for (var i = 0, length = Sys_MapAttrOfSelected.length; i < length; i++) {
                    if (item.KeyOfEn == Sys_MapAttrOfSelected[i].KeyOfEn && item.Name == Sys_MapAttrOfSelected[i].Name) {
                        flag = true;
                        break;
                    }
                }
                tallAppend += "<input id='" + item.KeyOfEn + "' type='checkbox' name='" + item.KeyOfEn + "' " + (flag ? " checked = 'checked'" : "") + "  />";
                tallAppend += "<label for='" + item.KeyOfEn + "'>" + item.Name + "(" + item.KeyOfEn + ")</label>";
                tallAppend += "</td>";

                if (index % 3 == 2) {
                    tallAppend += "</tr>";
                }
            });

            $("#tall").append(tallAppend);

        }

        function Save() {

            $("#Btn_Save").text("正在保存请稍候....");


            var checkBoxIDs = GetSelectedCheckIDs();

            // alert(checkBoxIDs);

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_RptDfine");
            handler.AddPara("RptNo", GetQueryString("RptNo"));
            handler.AddPara("FK_Flow", GetQueryString("FK_Flow"));

            handler.AddPara("Fields", checkBoxIDs);

            var data = handler.DoMethodReturnString("S2ColsChose_Save");
            //  alert(data);
            window.location.href = window.location.href;

        }

        //获得所有的checkbox 的id组成一个string用逗号分开, 以方便后台接受的值保存.
        function GetSelectedCheckIDs() {

            var checkBoxIDs = "";
            var arrObj = document.getElementsByTagName("input");

            for (var i = 0, len = arrObj.length; i < len; i++) {

                if (arrObj[i].type == 'checkbox') {
                    if (arrObj[i].checked)
                        checkBoxIDs += arrObj[i].id + ',';
                }
            }
            return checkBoxIDs;
        }

    </script>
</head>
<body>

    <table id="tsys" class='Table' style="width: 90%" cellpadding='2' cellspacing='2'>

        <tr>
            <td class='GroupTitle' colspan="3">
                系统字段:必选字段
            </td>
        </tr>
        <tr>
            <td style='width: 33%'>
                <input id="OID" type="checkbox" name="OID" checked="checked" disabled="disabled" /><label for="OID">WorkID(OID)</label>
            </td>
            <td style='width: 33%'>
                <input id="Title" type="checkbox" name="Title" checked="checked" disabled="disabled" /><label for="Title">标题(Title)</label>
            </td>
            <td style='width: 33%'>
                <input id="FlowEmps" type="checkbox" name="FlowEmps" checked="checked" disabled="disabled" /><label for="Title">参与人(FlowEmps)</label>
            </td>
        </tr>
        <tr>
            <td style='width: 33%' colspan="1">
                <input id="FlowStarter" type="checkbox" name="FlowStarter" checked="checked" disabled="disabled" /><label for="FlowStarter">发起人(FlowStarter)</label>
            </td>
            <td style='width: 33%' colspan="1">
                <input id="WFState" type="checkbox" name="WFState" checked="checked" disabled="disabled" /><label for="WFState">流程状态(WFState)</label>
            </td>
            <td style='width: 33%' colspan="1">
                <input id="FlowStartRDT" type="checkbox" name="FlowStartRDT" checked="checked" disabled="disabled" /><label for="FlowStartRDT">发起时间(FlowStartRDT)</label>
            </td>
        </tr>

        <tr>
            <td class='GroupTitle' colspan="3">
                系统字段：可选字段
            </td>
        </tr>
    </table>


    <table id="tall" class='Table' style="width: 90%" cellpadding='2' cellspacing='2'>
        <tr>
            <td class='GroupTitle' colspan="3">
                业务字段
            </td>
        </tr>
    </table>

    <br />

    <center>
        <button onclick="Save();" id="Btn_Save">保存</button>
    </center>

</body>
</html>
